import ValidateData
import datetime
import Model
import hashlib
from google.appengine.ext import db
from google.appengine.api import users

class User:
	def __init__(self, str):
		self.name = str 
		self.error = "NONE" 

	def createUser(self, gender, age, weight):
		userAcc = User.requireUserAccount()
		# md5Key = hashlib.md5(self.name).hexdigest()
		u = Model.UsersModel(name = self.name,
		gender = gender,
		age = age,
		weight = float(weight),
		created_at=datetime.datetime.now().date(),
		account=userAcc)
		u.put()

	def updateUser(self, name, gender, age, weight):
		user_object = ValidateData.getUserInfo(name)
		u = Model.UsersModel.get(user_object[0].key())
		u.age = age
		u.weight = weight
		u.gender = gender
		u.put()
	
	def deleteUser(self, name):
		user_object = ValidateData.getUserInfo(name)
		u = Model.UsersModel.get(user_object[0].key())
		u.delete()

	@staticmethod
	def requireUserAccount():
		'''Ask user to login if they are not loggedin''' 
		user = users.get_current_user()
		if user:
			user
		else:
			"None Registered User"